package jdbc;

import java.sql.*;
import java.util.Scanner;

public class JDBCDemo1 {
    public static void main(String[] args) throws SQLException, ClassNotFoundException {
        Scanner scanner = new Scanner(System.in);
        System.out.println("用户名:");
        String username = scanner.nextLine();
        System.out.println("密码:");
        String password = scanner.nextLine();
        System.out.println("昵称:");
        String nickname = scanner.nextLine();
        System.out.println("年龄:");
        int age = scanner.nextInt();

        Class.forName("com.mysql.cj.jdbc.Driver");
        Connection connection = DriverManager.getConnection("jdbc:mysql://localhost:3306/tedu", "root", "root");
        Statement statement = connection.createStatement();
        String sql = "INSERT INTO userinfo(username,password,nickname,age) VALUES('"+username+"','"+password+"','"+nickname+"',"+age+")";
        int i = statement.executeUpdate(sql);
        if (i>=1){
            System.out.println("Success");
        }else {
            System.out.println("Failed");
        }
        connection.close();
    }


}
